/***************************************************************************\
 * Copyright (C) by Keio University
 * main.cpp created in 11 2011.
 * Mail : fdesorbi@hvrl.ics.keio.ac.jp
 *
 * main.cpp is part of the HVRL Library.
 *
 * The HVRL Library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * The HVRL Library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
\***************************************************************************/

#include <hvrl/common/Common.hpp>
#include <hvrl/display/Tridelity-3D-Screen.hpp>

#include <iostream>

using namespace hvrl;

int main(int argc, char **argv)
{

    if(argc != 2)
    {
        Log::add().error("main","Missing parameters for the program");
        Log::add().info("tridility input-directory");
        return EXIT_FAILURE;
    }

    // Load 5 images from the input directory
    cv::Mat images[5];
    for(unsigned int i = 0; i < 5; ++i)
    {
        images[i] = cv::imread(std::string(argv[1])+"/stereo-"+numberToString(i+1)+".jpg");
        if(images[i].data == 0)
        {
            Log::add().error("main","Error while trying to open image "+std::string(argv[1])+"/stereo-"+numberToString(i+1)+".jpg");
        }
        cv::imwrite("stereotest-"+numberToString(i+1)+".jpg",images[i]);

        cv::cvtColor(images[i], images[i], CV_BGR2RGB);
        // Resize the image
        cv::resize(images[i],images[i],cv::Size(640,480));
    }

    std::cerr << "process" << std::endl;

    cv::Mat output;
    if(tridelity::createImage(images,output)==false)
    {
        return EXIT_FAILURE;
    }

    cv::cvtColor(output, output, CV_RGB2BGR);
    cv::imwrite("result.png",output);

    return EXIT_SUCCESS;
}

